<?php
require_once realpath (dirname (__FILE__) . '//..//..//pages.php');
require_once CLASS_A;
require_once CLASS_BR;
require_once CLASS_DIV;
require_once CLASS_H2;
require_once CLASS_IMG;
require_once CLASS_LI;
require_once CLASS_P;
require_once CLASS_SPAN;
require_once CLASS_UL;
require_once INC_DEFINES;
require_once INC_FUNCTIONS;
require_once MDL_STATS_FORM;

function classe ($ID = null) {
    require_once CLASS_CLASSE;
    $db = openConnection ();
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $classe = new Classe (array ('ID' => $ID));
        $classe->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $classe->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Studenti */
        $result = $db->select (array ('frequenta', 'studente'), array ('studente.ID', "CONCAT(studente.cognome, ' ', studente.nome) AS nome"), "frequenta.IDclasse='$ID' AND frequenta.IDstudente=studente.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Studenti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=studente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=studente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuno studente nella classe <b>' . $classe->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale classi: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ($_SESSION['stat'])));

        /* Classi per indirizzo */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Classi per indirizzo:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/classe/indirizzi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Studenti per classe */
        $p = new P();
        $p->add (new Span (array ('class' => 'label'), 'Studenti per classe:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/studente/classi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function distretto ($ID = null) {
    require_once CLASS_DISTRETTO;
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $distretto = new Distretto (array ('ID' => $ID));
        $distretto->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $distretto->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Scuole */
        $result = $db->select (array ('scuola', 'distretto'), array ('scuola.ID', 'scuola.nome'), "distretto.ID='$ID' AND scuola.IDdistretto=distretto.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Scuole:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=scuola&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=scuola&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna scuola nel distretto <b>' . $distretto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Ospedali */
        $result = $db->select (array ('ospedale', 'distretto'), array ('ospedale.ID', 'ospedale.nome'), "distretto.ID='$ID' AND ospedale.IDdistretto=distretto.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Ospedali:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=ospedale&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=ospedale&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun ospedale nel distretto <b>' . $distretto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale distretti: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('distretto')));

        /* Scuole per distretto */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Scuole per distretto:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/scuola/distretti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Ospedali per distretto */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Ospedali per distretto:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ospedale/distretti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function docente ($ID = null) {
    require_once CLASS_DOCENTE;
    $db = openConnection ();
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $docente = new Docente (array ('ID' => $ID));
        $docente->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $docente->get ('cognome') . ' ' . $docente->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Interventi */
        $result = $db->select (array ('intervento', 'docente', 'effettua'), array ('intervento.ID', 'intervento.data', 'intervento.ora'), "docente.ID='$ID' AND effettua.IDintervento=intervento.ID AND effettua.IDdocente=docente.ID", 'intervento.ID', 'intervento.data');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Interventi: (totale: '));
            $count = $db->count ('intervento', 'intervento.ID', "ID IN (SELECT intervento.ID FROM docente, effettua, intervento WHERE effettua.IDdocente=docente.ID AND effettua.IDintervento=intervento.ID AND docente.ID='$ID')");
            $sum = $db->sum ('intervento', 'durata', "ID IN (SELECT intervento.ID FROM docente, effettua, intervento WHERE effettua.IDdocente=docente.ID AND effettua.IDintervento=intervento.ID AND docente.ID='$ID')");
            if ($count == 0) {
                $count = '&#48';
            }
            if ($sum == 0) {
                $sum = '&#48';
            }
            $div->add (new Span (array ('class' => 'data'), $count . ', ' . $sum));
            $div->add (new Span (array ('class' => 'label'), ' minuti)'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new Span (
                                null,
                                $row['data'] . ' ' . $row['ora']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=intervento&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna data per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Materie */
        $result = $db->select (array ('materia', 'insegna', 'docente'), array ('DISTINCT materia.ID', 'materia.nome'), "docente.ID=$ID AND insegna.IDmateria=materia.ID AND insegna.IDdocente=docente.ID", null, 'materia.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Materie:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=materia&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=materia&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna materia per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Reparti */
        $result = $db->select (array ('reparto', 'effettua', 'docente'), array ('DISTINCT reparto.ID', 'reparto.nome'), "effettua.IDreparto=reparto.ID AND effettua.IDdocente=docente.ID AND docente.ID=$ID", 'reparto.ID', 'reparto.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Reparti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=reparto&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=reparto&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun reparto per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Ricoveri */
        $result = $db->select (array ('ricovero', 'effettua', 'docente'), array ('DISTINCT ricovero.ID', 'ricovero.nome'), "effettua.IDricovero=ricovero.ID AND effettua.IDdocente=docente.ID AND docente.ID=$ID", 'ricovero.ID', 'ricovero.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Ricoveri:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=ricovero&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=ricovero&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun ricovero per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Ospedali */
        $result = $db->select (array ('ospedale', 'effettua', 'docente'), array ('DISTINCT ospedale.ID', 'ospedale.nome'), "effettua.IDospedale=ospedale.ID AND effettua.IDdocente=docente.ID AND docente.ID=$ID", 'ospedale.ID', 'ospedale.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Ospedali:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=ospedale&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=ospedale&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun ospedale per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Scuole */
        $result = $db->select (array ('lavora_in', 'scuola', 'docente'), array ('DISTINCT scuola.ID', 'scuola.nome'), "docente.ID='$ID' AND lavora_in.IDscuola=scuola.ID AND lavora_in.IDdocente=docente.ID", 'scuola.ID', 'scuola.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Scuole:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=scuola&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=scuola&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna scuola per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());


        /* Studenti */
        $result = $db->select (array ('studente', 'docente', 'effettua'), array ('DISTINCT studente.ID', "CONCAT(studente.cognome, ' ', studente.nome) AS nome"), "docente.ID='$ID' AND effettua.IDstudente=studente.ID AND effettua.IDdocente=docente.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Studenti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=studente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=studente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun studente per il docente <b>' . $docente->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale docenti: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('docente')));

        $div->add (new Br ());

        /* Citta */
        $p = new P ();
        $row = $db->fetchAssoc ($db->select ('(SELECT DISTINCT citta FROM docente) AS tab', 'COUNT(citta) AS n'));
        $p->add (new Span (array ('class' => 'label'), 'Citt&agrave;: '));
        if ($row['n'] == 0) {
            $row['n'] = '&#48';
        }
        $p->add (new Span (array ('class' => 'data'), $row['n']));
        $p->add (new Br ());

        $result = $db->select ('docente', 'DISTINCT citta', null, null, 'citta');
        $ul = new Ul();
        while ($row = $db->fetchAssoc ($result)) {
            $ul->add (new Li (null, $row['citta']));
        }
        $p->add ($ul);
        $div->add ($p);

        /* Docenti per citta */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Docenti per citt&agrave;:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/docente/citta.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Docenti per sesso */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Docenti per sesso:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/docente/sesso.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Docenti per scuola */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Docenti per scuola:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/docente/scuole.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Docenti per materia */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Docenti per materia:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/docente/materie.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Interventi per docente */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Interventi per docente:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/docenti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], array ('cognome', 'nome'))));

    return $div;
}

function indirizzo ($ID = null) {
    require_once CLASS_INDIRIZZO;
    $db = openConnection ();
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $indirizzo = new Indirizzo (array ('ID' => $ID));
        $indirizzo->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $indirizzo->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Classi */
        $result = $db->select (array ('classe', 'frequenta', 'indirizzo'), array ('DISTINCT classe.ID', 'classe.nome'), "indirizzo.ID='$ID' AND frequenta.IDclasse=classe.ID AND frequenta.IDindirizzo=indirizzo.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Classi:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=classe&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=classe&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna classe per l&apos;indirizzo <b>' . $indirizzo->get ('nome') . '</b>'));
        }
        $div->add (new Br ());


        /* Scuole */
        $result = $db->select (array ('scuola', 'frequenta', 'indirizzo'), array ('DISTINCT scuola.ID', 'scuola.nome'), "indirizzo.ID='$ID' AND frequenta.IDscuola=scuola.ID AND frequenta.IDindirizzo=indirizzo.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Scuole:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=scuola&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=scuola&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna scuola per l&apos;indirizzo <b>' . $indirizzo->get ('nome') . '</b>'));
        }
        $div->add (new Br ());

        /* Studenti */
        $result = $db->select (array ('studente', 'frequenta', 'indirizzo'), array ('DISTINCT studente.ID', "CONCAT(studente.cognome, ' ', studente.nome) AS nome"), "indirizzo.ID='$ID' AND frequenta.IDstudente=studente.ID AND frequenta.IDindirizzo=indirizzo.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Studenti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=studente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=studente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun studente per l&apos;indirizzo <b>' . $indirizzo->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale indirizzi: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('indirizzo')));

        $div->add (new Br ());

        /* Classi per indirizzo */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Classi per indirizzo:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/classe/indirizzi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Scuole per indirizzo */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Scuole per indirizzo:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/scuola/indirizzi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Studenti per indirizzo */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Studenti per indirizzo:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/studente/indirizzi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function intervento ($ID = null) {
    require_once CLASS_INTERVENTO;
    $db = openConnection ();
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        ?><meta http-equiv="refresh" content="0;url='<?php echo HTTP_CTRL_MAIN . "?request=view&table=intervento&values=$ID"; ?>'" /><?php
    } else {
        $div->add (new Span (array ('class' => 'label'), 'Totale interventi: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('intervento') . ', ' . $db->sum ('intervento', 'durata')));
        $div->add (new Span (array ('class' => 'label'), 'minuti<br />'));

        $container = new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], array ('data', 'ora')));
        $container->add (formInterventoDocenti ());
        $container->add (formInterventoStudenti ());
        $div->add ($container);

        /* Interventi per docente */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per docente:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/docenti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Interventi per materia */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per materia:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/materie.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Interventi per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Interventi per studente */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per studente:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/studenti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Interventi per tipo */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per tipo:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/tipi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    return $div;
}

function interventoDocente ($values) {
    if (isset ($values['IDdocente'])) {
        require_once CLASS_DOCENTE;
        require_once CLASS_LI;
        require_once CLASS_UL;

        $ID = $values['IDdocente'];
        $db = openConnection ();
        $div = new Div (array ('id' => 'stats'));

        $docente = new Docente ($values);
        $docente->reload ();
        $div->add (new Span (array ('class' => 'label'), 'Docente: '));
        $div->add (new Span (array ('class' => 'data'), $docente->get ('cognome') . ' ' . $docente->get ('nome')));
        $div->add (new Br ());

        $count = $db->fetchAssoc ($db->select (array ('docente', 'effettua'), 'COUNT(*) AS n', "effettua.IDdocente=docente.ID AND docente.ID=$ID"));
        $sum = $db->fetchAssoc ($db->select (array ('docente', 'effettua', 'intervento'), 'SUM(intervento.durata) AS sum', "effettua.IDintervento=intervento.ID AND effettua.IDdocente=docente.ID AND docente.ID=$ID"));
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale interventi: '));
        if ($count['n'] == 0) {
            $count['n'] = '&#48'; //doesn't print 0 character!
        }
        if ($sum['sum'] == 0) {
            $sum['sum'] = '&#48'; //doesn't print 0 character!
        }
        $div->add (new Span (array ('class' => 'data'), $count['n'] . ', ' . $sum['sum']));
        $div->add (new Span (array ('class' => 'label'), 'minuti'));

        $result = $db->select (array ('docente', 'effettua', 'intervento'), array ('intervento.ID', 'intervento.data', 'intervento.ora'), "effettua.IDdocente=docente.ID AND effettua.IDintervento=intervento.ID AND docente.ID=$ID", null, 'intervento.data');
        if ($result) {
            $p = new P();
            $p->add (new Span (array ('class' => 'label'), 'Date: '));
            $ul = new Ul ();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new Span (
                                null,
                                $row['data'] . ' ' . $row['ora']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=intervento&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $p->add ($ul);
            $div->add ($p);
        } if ($flag) {
            $div->add (new P (null, 'Nessuna data da mostrare!'));
        }
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=intervento'), 'Torna alle statistiche generali'));

        return $div;
    }
    return false;
}

function interventoStudente ($values) {
    if (isset ($values['IDstudente'])) {
        require_once CLASS_LI;
        require_once CLASS_UL;

        $ID = $values['IDstudente'];
        $db = openConnection (false);
        $div = new Div (array ('id' => 'stats'));

        $row = $db->fetchAssoc ($db->select (array ('studente', 'effettua'), 'COUNT(*) AS n', "effettua.IDstudente=studente.ID AND studente.ID=$ID"));
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale: '));
        if ($row['n'] == 0) {
            $row['n'] = '&#48'; //doesn't print 0 character!
        }
        $div->add (new Span (array ('class' => 'data'), $row['n']));

        $result = $db->select (array ('studente', 'effettua', 'intervento'), array ('intervento.ID', 'intervento.data', 'intervento.ora'), "effettua.IDstudente=studente.ID AND effettua.IDintervento=intervento.ID AND studente.ID=$ID", null, 'intervento.data');
        if ($result) {
            $p = new P();
            $p->add (new Span (array ('class' => 'label'), 'Date: '));
            $ul = new Ul ();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new Span (
                                null,
                                $row['data'] . ' ' . $row['ora']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=intervento&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $p->add ($ul);
            $div->add ($p);
        } if ($flag) {
            $div->add (new P (null, 'Nessuna data da mostrare!'));
        }

        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=intervento'), 'Torna alle statistiche generali'));
        return $div;
    }
    return false;
}

function materia ($ID = null) {
    require_once CLASS_MATERIA;
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $materia = new Materia (array ('ID' => $ID));
        $materia->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $materia->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Docenti */
        $result = $db->select (array ('docente', 'insegna', 'materia'), array ('docente.ID', "CONCAT(docente.cognome, ' ', docente.nome) AS nome"), "materia.ID='$ID' AND insegna.IDmateria=materia.ID AND insegna.IDdocente=docente.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Docenti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=docente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=docente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun docente per la materia <b>' . $materia->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale materie: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('materia')));
        $div->add (new Br ());

        /* Docenti per materia */
        $div->add (new Span (array ('class' => 'label'), 'Docenti per materia:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/docente/materie.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Interventi per materia */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per materia:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/materie.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function ospedale ($ID = null) {
    require_once CLASS_OSPEDALE;
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $ospedale = new Ospedale (array ('ID' => $ID));
        $ospedale->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $ospedale->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Docenti */
        $result = $db->select (array ('docente', 'ospedale', 'effettua'), array ('docente.ID', "CONCAT(docente.cognome, ' ', docente.nome) AS nome"), "ospedale.ID='$ID' AND effettua.IDdocente=docente.ID AND effettua.IDospedale=ospedale.ID", 'nome', 'docente.ID');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Docenti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=docente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=docente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna data per il docente <b>' . $ospedale->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));

        /* Interventi */
        $result = $db->select (array ('intervento', 'ospedale', 'effettua'), array ('intervento.ID', 'intervento.data', 'intervento.ora'), "ospedale.ID='$ID' AND effettua.IDintervento=intervento.ID AND effettua.IDospedale=ospedale.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Interventi: (totale: '));
            $count = $db->count ('intervento', 'intervento.ID', "ID IN (SELECT intervento.ID FROM ospedale, effettua, intervento WHERE effettua.IDospedale=ospedale.ID AND effettua.IDintervento=intervento.ID AND ospedale.ID='$ID')");
            $sum = $db->sum ('intervento', 'durata', "ID IN (SELECT intervento.ID FROM ospedale, effettua, intervento WHERE effettua.IDospedale=ospedale.ID AND effettua.IDintervento=intervento.ID AND ospedale.ID='$ID')");
            if ($count == 0) {
                $count = '&#48';
            }
            if ($sum == 0) {
                $sum = '&#48';
            }
            $div->add (new Span (array ('class' => 'data'), $count . ', ' . $sum));
            $div->add (new Span (array ('class' => 'label'), ' minuti)'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new Span (
                                null,
                                $row['data'] . ' ' . $row['ora']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=intervento&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna data per il docente <b>' . $ospedale->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Reparti */
        $result = $db->select (array ('reparto', 'effettua', 'ospedale'), array ('DISTINCT reparto.ID', 'reparto.nome'), "effettua.IDreparto=reparto.ID AND effettua.IDospedale=ospedale.ID AND ospedale.ID=$ID", 'reparto.nome', 'reparto.ID');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Reparti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=reparto&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=reparto&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun reparto per l&apos;ospedale <b>' . $ospedale->get ('cognome') . ' ' . $docente->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale ospedali: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('ospedale')));
        $div->add (new Br ());

        /* Citta */
        $p = new P ();
        $row = $db->fetchAssoc ($db->select ('(SELECT DISTINCT citta FROM ospedale) AS tab', 'COUNT(citta) AS n'));
        $p->add (new Span (array ('class' => 'label'), 'Citt&agrave;: '));
        if ($row['n'] == 0) {
            $row['n'] = '&#48';
        }
        $p->add (new Span (array ('class' => 'data'), $row['n']));
        $p->add (new Br ());

        $result = $db->select ('ospedale', 'DISTINCT citta', null, null, 'citta');
        $ul = new Ul();
        while ($row = $db->fetchAssoc ($result)) {
            $ul->add (new Li (null, $row['citta']));
        }
        $p->add ($ul);
        $div->add ($p);

        /* Docenti attivi per ospedale */
        /* $div->add (new Span (array ('class' => 'label'), 'Docenti attivi per ospedale :'));
          $div->add (new Img (array (
          'alt' => 'Invalid or insufficent data!',
          'height' => IMG_HEIGHT,
          'src' => HTTP_DIR_IMG . '/docente/ospedali.php',
          'width' => IMG_WIDTH
          )
          )
          );
          $div->add (new Br ()); *///Doesn't work correctely

        /* Interventi per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Ospedali per distretto */
        $div->add (new Span (array ('class' => 'label'), 'Ospedali per distretto:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ospedale/distretti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Reparti per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Reparti per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/reparto/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
        
        /* Ricoveri per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function permesso () {
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    /* Totale */
    $div->add (new Span (array ('class' => 'label'), 'Totale permessi: '));
    $div->add (new Span (array ('class' => 'data'), $db->count ('permesso')));
    $div->add (new Br ());

    return $div;
}

function reparto ($ID = null) {
    require_once CLASS_REPARTO;
    $db = openConnection ();
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $reparto = new Reparto (array ('ID' => $ID));
        $reparto->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $reparto->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());
        
        /* Docenti */
        $result = $db->select (array ('docente', 'reparto', 'effettua'), array ('docente.ID', "CONCAT(docente.cognome, ' ', docente.nome) AS nome"), "reparto.ID='$ID' AND effettua.IDdocente=docente.ID AND effettua.IDreparto=reparto.ID", 'docente.ID', 'nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Docenti: '));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=docente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=docente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuno docente per il reparto <b>' . $reparto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());
        
        /* Ospedali */
        $result = $db->select (array ('ospedale', 'reparto', 'effettua'), array ('ospedale.ID', 'ospedale.nome'), "reparto.ID='$ID' AND effettua.IDospedale=ospedale.ID AND effettua.IDreparto=reparto.ID", 'ospedale.ID', 'ospedale.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Ospedali: '));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=ospedale&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=ospedale&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessun ospedale per il reparto <b>' . $reparto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());
        
        /* Ricoveri */
        $result = $db->select (array ('ricovero', 'reparto', 'effettua'), array ('ricovero.ID', 'ricovero.nome'), "reparto.ID='$ID' AND effettua.IDricovero=ricovero.ID AND effettua.IDreparto=reparto.ID", 'ricovero.ID', 'ricovero.nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Ricoveri: '));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=ricovero&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=ricovero&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuno ricovero per il reparto <b>' . $reparto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Studenti */
        $result = $db->select (array ('studente', 'reparto', 'effettua'), array ('studente.ID', "CONCAT(studente.cognome, ' ', studente.nome) AS nome"), "reparto.ID='$ID' AND effettua.IDstudente=studente.ID AND effettua.IDreparto=reparto.ID", 'studente.ID', 'nome');
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Studenti: '));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new A (array (
                            'href' => HTTP_CTRL_MAIN . '?stat=studente&ID=' . $row['ID'],
                            'title' => 'Statistiche'
                                ),
                                $row['nome']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=studente&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuno studente per il reparto <b>' . $reparto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());

        /* Interventi */
        $result = $db->select (array ('intervento', 'reparto', 'effettua'), array ('intervento.ID', 'intervento.data', 'intervento.ora'), "reparto.ID='$ID' AND effettua.IDintervento=intervento.ID AND effettua.IDreparto=reparto.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Interventi: (totale: '));
            $count = $db->count ('intervento', 'intervento.ID', "ID IN (SELECT intervento.ID FROM reparto, effettua, intervento WHERE effettua.IDreparto=reparto.ID AND effettua.IDintervento=intervento.ID AND reparto.ID='$ID')");
            $sum = $db->sum ('intervento', 'durata', "ID IN (SELECT intervento.ID FROM reparto, effettua, intervento WHERE effettua.IDreparto=reparto.ID AND effettua.IDintervento=intervento.ID AND reparto.ID='$ID')");
            if ($sum == 0) {
                $sum = '&#48';
            }
            if ($count == 0) {
                $count = '&#48';
            }
            $div->add (new Span (array ('class' => 'data'), $count . ', ' . $sum));
            $div->add (new Span (array ('class' => 'label'), ' minuti)'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $li = new Li();
                $li->add (new Span (
                                null,
                                $row['data'] . ' ' . $row['ora']
                        )
                );
                $li->add (new A (
                                array (
                                    'href' => HTTP_CTRL_MAIN . '?request=view&table=intervento&values=' . $row['ID']
                                ),
                                new Img (
                                        array (
                                            'src' => HTTP_IMG_VIEW,
                                            'title' => 'Dettagli'
                                        )
                                )
                ));
                $ul->add ($li);
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna data per il reparto <b>' . $reparto->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale reparti: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('reparto')));
        $div->add (new Br ());

        /* Docenti per reparto */
        $div->add (new Span (array ('class' => 'label'), 'Docenti per reparto:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/docente/reparti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Interventi per reparto */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per reparto:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/reparti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Ricoveri per reparto */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per reparto:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/reparti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Reparti per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Reparti per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/reparto/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function ricovero ($ID = null) {
    require_once CLASS_RICOVERO;
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));
    if ($ID) {
        ?><meta http-equiv="refresh" content="0;url='<?php echo HTTP_CTRL_MAIN . "?request=view&table=ricovero&values=$ID"; ?>'" /><?php
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale ricoveri: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('ricovero')));
        $div->add (new Br ());
        $div->add (new Br ());
        
        /* Ricoveri per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
        
        /* Ricoveri per studente */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per studente:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/studenti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Ricoveri per tipo */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per tipo:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/tipi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function scuola ($ID = null) {
    require_once CLASS_SCUOLA;
    $db = openConnection ();
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        $scuola = new Scuola (array ('ID' => $ID));
        $scuola->reload ();

        /* title */
        $a = new A (
                        array (
                            'href' => HTTP_CTRL_MAIN . "?request=view&values=$ID&table=" . $_SESSION['stat'],
                            'title' => 'Dettagli'
                        ),
                        $scuola->get ('nome')
        );
        $a->add (new Img (
                        array ('src' => HTTP_IMG_VIEW)
                )
        );
        $div->add (new H2 (
                        null,
                        $a
                )
        );
        $div->add (new Br ());

        /* Studenti */
        $result = $db->select (array ('frequenta', 'studente'), array ('studente.ID', "CONCAT(studente.cognome, ' ', studente.nome) AS nome"), "frequenta.IDscuola='$ID' AND frequenta.IDstudente=studente.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Studenti:'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $ul->add (new Li (null, '<a href="' . HTTP_CTRL_MAIN . '?request=view&table=studente&values=' . $row['ID'] . '">' . $row['nome'] . '</a>'));
            }
            $div->add ($ul);
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuno studente nella scuola <b>' . $scuola->get ('nome') . '</b>'));
        }
        $div->add (new Br ());
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale scuole: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('scuola')));
        $div->add (new Br ());
        $div->add (new Br ());
        
        /* Classi per scuola */
        $div->add (new Span (array ('class' => 'label'), 'Classi per scuola:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/classe/scuole.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
        
        /* Indirizzi per scuola */
        $div->add (new Span (array ('class' => 'label'), 'Indirizzi per scuola:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/indirizzo/scuole.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
        
        /* Scuole per distretto */
        $p = new P ();
        $p->add (new Span (array ('class' => 'label'), 'Scuole per distretto:<br />'));
        $p->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/scuola/distretti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add ($p);

        /* Studenti per scuola */
        $div->add (new Span (array ('class' => 'label'), 'Studenti per scuola:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/studente/scuole.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function studente ($ID = null) {
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        /* Interventi */
        $result = $db->select (array ('intervento', 'studente', 'effettua'), array ('intervento.ID', 'intervento.data', 'intervento.ora'), "studente.ID='$ID' AND effettua.IDintervento=intervento.ID AND effettua.IDstudente=studente.ID");
        if ($result) {
            $div->add (new Span (array ('class' => 'label'), 'Interventi: (totale: '));
            $count = $db->count ('intervento', 'intervento.ID', "ID IN (SELECT intervento.ID FROM studente, effettua, intervento WHERE effettua.IDstudente=studente.ID AND effettua.IDintervento=intervento.ID AND studente.ID='$ID')");
            $sum = $db->sum ('intervento', 'durata', "ID IN (SELECT intervento.ID FROM studente, effettua, intervento WHERE effettua.IDstudente=studente.ID AND effettua.IDintervento=intervento.ID AND studente.ID='$ID')");
            if ($sum == 0) {
                $sum = '&#48';
            }
            if ($count == 0) {
                $count = '&#48';
            }
            $div->add (new Span (array ('class' => 'data'), $count . ', ' . $sum));
            $div->add (new Span (array ('class' => 'label'), ' minuti)'));
            $ul = new Ul();
            $flag = true;
            while ($row = $db->fetchAssoc ($result)) {
                $flag = false;
                $ul->add (new Li (null, '<a href="' . HTTP_CTRL_MAIN . '?request=view&table=intervento&values=' . $row['ID'] . '">' . $row['data'] . ' ' . $row['ora'] . '</a>'));
            }
            $div->add ($ul);
        } else {
            $flag = true;
        } if ($flag) {
            $div->add (new Span (array ('class' => 'data'), 'Nessuna data per il reparto <b>' . $reparto->get ('nome') . '</b>'));
        }
        $div->add (new A (array ('class' => 'fixed stat', 'href' => HTTP_CTRL_MAIN . '?stat=' . $_SESSION['stat']), 'Torna alle statistiche generali'));
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale studenti: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('scuola')));
        $div->add (new Br ());
        $div->add (new Br ());
        
        /* Interventi per studente */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per studente:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/studenti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
        
        /* Ricoveri per studente */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per studente:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/studenti.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
        
        /* Studenti per scuola */
        $div->add (new Span (array ('class' => 'label'), 'Studenti per scuola:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/studente/scuole.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

        /* Studenti per ospedale */
        $div->add (new Span (array ('class' => 'label'), 'Studenti per ospedale:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/studente/ospedali.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());

    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], array ('cognome', 'nome'))));

    return $div;
}

function tipo_intervento ($ID = null) {
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        ?><meta http-equiv="refresh" content="0;url='<?php echo HTTP_CTRL_MAIN . "?request=view&table=tipo_intervento&values=$ID"; ?>'" /><?php
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale tipi intervento: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('tipo_intervento')));
        $div->add (new Br ());

        /* Interventi per tipo */
        $div->add (new Span (array ('class' => 'label'), 'Interventi per tipo:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/intervento/tipi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function tipo_ricovero ($ID = null) {
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        ?><meta http-equiv="refresh" content="0;url='<?php echo HTTP_CTRL_MAIN . "?request=view&table=tipo_ricovero&values=$ID"; ?>'" /><?php
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale tipi ricovero: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('tipo_ricovero')));
        $div->add (new Br ());

        /* Ricoveri per tipo */
        $div->add (new Span (array ('class' => 'label'), 'Ricoveri per tipo:<br />'));
        $div->add (new Img (array (
                    'alt' => 'Invalid or insufficent data!',
                    'height' => IMG_HEIGHT,
                    'src' => HTTP_DIR_IMG . '/ricovero/tipi.php',
                    'width' => IMG_WIDTH
                        )
                )
        );
        $div->add (new Br ());
    }


    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'nome')));

    return $div;
}

function user ($ID = null) {
    $db = openConnection (false);
    $div = new Div (array ('id' => 'stats'));

    if ($ID) {
        ?><meta http-equiv="refresh" content="0;url='<?php echo HTTP_CTRL_MAIN . "?request=view&table=user&values=$ID"; ?>'" /><?php
    } else {
        /* Totale */
        $div->add (new Span (array ('class' => 'label'), 'Totale utenti: '));
        $div->add (new Span (array ('class' => 'data'), $db->count ('user')));
        $div->add (new Br ());
    }

    $div->add (new Div (array ('class' => 'container'), formMostra ($_SESSION['stat'], 'username')));

    return $div;
}
?>
